package net.guerlab.sdk.anubis.sign;

import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 签名助手
 * 
 * @author guer
 *
 */
public class SignHelper {

    private static final Logger LOGGER = LoggerFactory.getLogger(SignHelper.class);

    /**
     * 获取签名
     * 
     * @param appId
     *            应用ID
     * @param accessToken
     *            accessToken
     * @param salt
     *            随机数
     * @param data
     *            数据json
     * @return 签名内容
     */
    public static String generateBusinessSign(
            String appId,
            String accessToken,
            String salt,
            String data) {
        StringBuilder seed = new StringBuilder();

        seed.append("app_id=");
        seed.append(appId);
        seed.append("&access_token=");
        seed.append(accessToken);
        seed.append("&data=");
        seed.append(data);
        seed.append("&salt=");
        seed.append(salt);

        String queryString = seed.toString();

        LOGGER.debug("query string is {}", queryString);

        return DigestUtils.md5Hex(queryString);
    }
}
